package com.tarena.dang.actions.user;

import com.tarena.dang.actions.BaseAction;
import com.tarena.dang.pojos.User;
import com.tarena.dang.services.UserService;
import com.tarena.dang.services.impl.UserServiceImpl;
import com.tarena.dang.utils.Constant;

public class RegisterAction extends BaseAction {
	private User user;
	private String password1;

	public String execute() {
		if (!user.getPassword().equals(password1)
				|| user.getPassword().equals("") || user.getPassword() == null) {
			return "fail";
		}
		try {
			UserService service = new UserServiceImpl();
			service.register(user, httpRequest.getRemoteAddr());
			session.put(Constant.USER, user);
			return "verify";
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}

	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	public void setPassword1(String password1) {
		this.password1 = password1;
	}

	public String getPassword1() {
		return password1;
	}
}
